#include "mainform.h"

MainForm::MainForm(QWidget *parent) : QWidget(parent){
    //UI
    connectButton = new QPushButton("连  接",parent);//连接
    structureButton = new QPushButton("结构参数",parent);//结构参数
    coeffButton = new QPushButton("偏心参数",parent);//偏心参数
    explanationButton = new QPushButton("说  明",parent);//说明
    calibrationLabel = new QLabel("标定程序",parent);//标定程序
    correctionLabel = new QLabel("通讯程序",parent);//验证程序
    tcpLabel = new QLabel("验证程序",parent);//测头程序
    calibrationLOGO = new QLabel(parent);
    correctionLOGO = new QLabel(parent);
    coordinateLOGO = new QLabel(parent);
    mGridLayout  = new QGridLayout(parent);
}
void MainForm::SetMainForm(QWidget *parent){
    parent->setWindowTitle("ACMM Comprehensive SoftWare System");
    parent->setMaximumSize(1340,600);
    parent->setMinimumSize(1320,580);
    connectButton->setMaximumSize(100,50);
    connectButton->setMinimumSize(100,40);
    structureButton->setMaximumSize(100,50);
    structureButton->setMinimumSize(100,40);
    coeffButton->setMaximumSize(100,50);
    coeffButton->setMinimumSize(100,40);
    explanationButton->setMaximumSize(100,50);
    explanationButton->setMinimumSize(100,40);
    calibrationLabel->setMaximumSize(100,60);
    calibrationLabel->setMinimumSize(80,50);
    correctionLabel->setMaximumSize(100,60);
    correctionLabel->setMinimumSize(80,50);
    tcpLabel->setMaximumSize(100,60);
    tcpLabel->setMinimumSize(80,50);
    QFont Font_comprehensive;
    Font_comprehensive.setFamily("Microsoft YaHei");
    Font_comprehensive.setBold(false);
    Font_comprehensive.setPixelSize(20);
    //字体设置
    connectButton->setFont(Font_comprehensive);
    structureButton->setFont(Font_comprehensive);
    coeffButton->setFont(Font_comprehensive);
    explanationButton->setFont(Font_comprehensive);
    calibrationLabel->setFont(Font_comprehensive);
    correctionLabel->setFont(Font_comprehensive);
    tcpLabel->setFont(Font_comprehensive);
    calibrationImage.load("://image/calibrate.png");
    calibrationImage.scaled(380,400,Qt::KeepAspectRatio);
    calibrationLOGO->setPixmap(QPixmap::fromImage(calibrationImage));
    correctionImage.load("://image/verify.png");
    correctionImage.scaled(380,400,Qt::KeepAspectRatio);
    correctionLOGO->setPixmap(QPixmap::fromImage(correctionImage));
    tcpImage.load("://image/xyz.png");
    tcpImage.scaled(380,400,Qt::KeepAspectRatio);
    coordinateLOGO->setPixmap(QPixmap::fromImage(tcpImage));
    //第一行
    mGridLayout->addWidget(connectButton,0,0,1,3,Qt::AlignHCenter|Qt::AlignCenter);
    mGridLayout->addWidget(structureButton,0,3,1,3,Qt::AlignHCenter|Qt::AlignCenter);
    mGridLayout->addWidget(coeffButton,0,6,1,3,Qt::AlignHCenter|Qt::AlignCenter);
    mGridLayout->addWidget(explanationButton,0,9,1,3,Qt::AlignHCenter|Qt::AlignCenter);
    //第二行
    mGridLayout->addWidget(calibrationLOGO,1,0,1,4,Qt::AlignHCenter|Qt::AlignCenter);
    mGridLayout->addWidget(coordinateLOGO,1,4,1,4,Qt::AlignHCenter|Qt::AlignCenter);
    mGridLayout->addWidget(correctionLOGO,1,8,1,4,Qt::AlignHCenter|Qt::AlignCenter);
    //第三行
    mGridLayout->addWidget(calibrationLabel,2,0,1,4,Qt::AlignHCenter|Qt::AlignCenter);
    mGridLayout->addWidget(correctionLabel,2,4,1,4,Qt::AlignHCenter|Qt::AlignCenter);
    mGridLayout->addWidget(tcpLabel,2,8,1,4,Qt::AlignHCenter|Qt::AlignCenter);
    // 设置水平间距
    mGridLayout->setHorizontalSpacing(40);
    // 设置垂直间距
    mGridLayout->setVerticalSpacing(15);
    mGridLayout->setContentsMargins(10, 10, 10, 10);
    //三个Label安装事件过滤器
    calibrationLOGO->installEventFilter(parent);//安装事件过滤器
    coordinateLOGO->installEventFilter(parent);
    parent->setLayout(mGridLayout);
}
void MainForm::setStructEnabled(bool arg){
    structureButton->setEnabled(arg);
}
void MainForm::setCoeffEnabled(bool arg){
    coeffButton->setEnabled(arg);
}
void MainForm::setExplanEnabled(bool arg){
    explanationButton->setEnabled(arg);
}
bool MainForm::isCalibPartEnable(QObject *obj){
    return obj == calibrationLOGO ? true : false;
}
bool MainForm::isCoordiPartEnable(QObject *obj){
    return obj == coordinateLOGO ? true : false;
}
/*************************************为对应应用部分的信号和槽服务(封装性和耦合性不好)********************************************/
QPushButton * MainForm::getConnectButtonPointer() const{
    if(connectButton == nullptr){
        return nullptr;
    }
    return connectButton;
}
QPushButton * MainForm::getStructButtonPointer() const{
    if(structureButton == nullptr){
        return nullptr;
    }
    return structureButton;
}
QPushButton * MainForm::getCoeffButtonPointer() const{
    if(coeffButton == nullptr){
        return nullptr;
    }
    return coeffButton;
}
QPushButton * MainForm::getExplanButtonPointer() const{
    if(explanationButton == nullptr){
        return nullptr;
    }
    return explanationButton;
}
